package com.haixiaoke.saas.order.state.role;

import com.haixiaoke.saas.common.constant.OrderConstants;
import com.haixiaoke.saas.common.enums.OrderStateEnum;
import com.haixiaoke.saas.common.utils.DateUtils;
import com.haixiaoke.saas.order.domain.Order;
import com.haixiaoke.saas.order.state.server.IOrderStateServerRole;

/**
 * 待付款状态服务实现类
 *
 * @author panda
 * @Date 2024/4/16
 **/
public class PayOrderOrderStateServerRole extends AbstractSpecificOrderOrderStateServerRole {

    public PayOrderOrderStateServerRole(IOrderStateServerRole stateServerRole) {
        super(stateServerRole);
    }

    /**
     * 待付款->已支付
     *
     * @param order
     */
    @Override
    public int orderStayCheckIn(Order order, String remark) {
        addOrderStateRecord(order.getOrderId(), order.getOrderState(), OrderStateEnum.ORDER_STATE_STAY_CHECK_IN.getValue(), OrderConstants.RECORD_SOURCE_CONSUMER, remark, order.getOperatorId());
        order.setOrderState(OrderStateEnum.ORDER_STATE_STAY_CHECK_IN.getValue());
        order.setPayTime(DateUtils.getNowDate());
        return orderService.updateOrderBySystem(order);
    }

    /**
     * 待付款->取消支付
     *
     * @param order
     */
    @Override
    public int orderCancellation(Order order, String recordSource, String recordReason) {
        addOrderStateRecord(order.getOrderId(), order.getOrderState(), OrderStateEnum.ORDER_STATE_CANCEL_PAY.getValue(), recordSource, recordReason, order.getOperatorId());
        order.setOrderState(OrderStateEnum.ORDER_STATE_CANCEL_PAY.getValue());
        return orderService.updateOrderBySystem(order);
    }
}
